<?php
namespace Admin\Controller;
class PayeeController extends AdminController{
	//抵押资料
    protected function _initialize() {
		parent::_initialize ();
	}
	public function index()
	{
		$list=$this->getList('*','payee','1=1');
		foreach ($list as $k => $v) {
			$group=$this->getInfo('*','group','id='.$v['gid']);
			$list[$k]['groupname']=$group['name'];
		}
		$this->assign('list',$list);
		$this->display();
	}

	//添加收款单位
	public function add()
	{
	  if(IS_POST){
	  	$info=$this->getInfo('*','payee','bank_card='.'"'.$_POST['bankCard'].'"');
	  	if($info){
          $this->error('该银行卡账号已存在');
	  	}
	  	$data=array(
			'name'      => $_POST['payee_name'],
			'add_time'  => time(),
			'status'    => $_POST['status'],
			'gid'       => $_POST['gid'],
			'bank_name' => $_POST['bankName'],
			'bank_card' => $_POST['bankCard'],
	  		);
	  	$result = $this->updateData($data, 'payee');
		$this->returnResult($result);
	  }
	  $group=$this->getList('*','group','status=1 and pid=0 and work_status=1');
	  $this->assign('group',$group);
	  $this->display();
	}

	//修改收款单位
	public function edit()
	{
		if(IS_POST){
          	$data=array(
				'name'      => $_POST['payee_name'],
				'status'    => $_POST['status'],
				'gid'       => $_POST['gid'],
				'bank_name' => $_POST['bankName'],
				'bank_card' => $_POST['bankCard'],
	  		);
	  		$result=M('payee')->where('id='.I('post.id'))->save($data);
	  		$this->returnResult($result);
		}else{
			$info=$this->getInfo('*','payee','id='.I('get.id',0,'intval'));
			$group=$this->getList('*','group','status=1 and pid=0 and work_status=1');
	        $this->assign('group',$group);
			$this->assign('info',$info);
			$this->display('add');
		}
	}

	//删除收款单位
	public function del()
	{
		$result = $this->deleteData('id=' . I('get.id', 0, 'intval'), 'payee');
		$this->returnResult($result);
	}


}